package com.cadre.web.controller.officer;

import com.alibaba.fastjson.JSONObject;
import com.cadre.common.utils.R;
import com.cadre.common.utils.oldutil.DateUtil;
import com.cadre.system.domain.officer.A01;
import com.cadre.system.domain.officer.PX_PXBXX;
import com.cadre.system.service.A01Service;
import com.cadre.system.service.PX_ReportService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Api(tags = {"A-培训报表接口"})
@RequestMapping({"/profess/PX_Report"})
@RestController
/* loaded from: PX_ReportController.class */
public class PX_ReportController {
    @Autowired
    PX_ReportService pxSer;
    @Autowired
    private A01Service a01Service;

    @GetMapping({"/getListForPage"})
    @ApiOperation("培训报表查询")
    public R getListForPage(@RequestParam Map<String, Object> map) {
        if (map.get("startTime") == null || map.get("endTime") == null || map.get("startTime").toString().length() == 0 || map.get("startTime").toString().length() == 0) {
            map.put("qj", "");
        } else {
            map.put("qj", map.get("startTime") + "-" + map.get("endTime"));
        }
        return R.ok().put("page", (Object) this.pxSer.getListForPage(map));
    }

    @GetMapping({"/getPXbyPersonId/{personid}"})
    @ApiOperation("培训情况统计表-个人")
    public R getPXbyPersonId(@PathVariable String personid) {
        JSONObject j = new JSONObject();
        List<Map<String, Object>> listMap = new ArrayList<>();
        List<Map<String, Object>> listMap2 = new ArrayList<>();
        Map<String, Object> map = new HashMap<>();
        A01 a = (A01) this.a01Service.getById(personid);
        j.put("a0101", a.getA0101());
        j.put("a0106", a.getA0106());
        j.put("a0183", a.getA0183());
        j.put("a0179", a.getA0179());
        j.put("a0180", a.getA0180());
        List<PX_PXBXX> list = this.pxSer.getListByPersonid(personid);
        short year = 0;
        short yearTime = 0;
        short sumTime = 0;
        if (list.size() > 0) {
            year = list.get(0).getPxnd().shortValue();
            map.put("year", Short.valueOf(year));
        }
        for (int i = 0; i < list.size(); i++) {
            if (year == list.get(i).getPxnd().shortValue()) {
                yearTime = (short) (yearTime + list.get(i).getXs().shortValue());
            } else {
                map.put("year", Short.valueOf(year));
                map.put("yearTime", Short.valueOf(yearTime));
                map.put("pxList", listMap2);
                listMap.add(map);
                year = list.get(i).getPxnd().shortValue();
                map = new HashMap<>();
                listMap2 = new ArrayList<>();
                yearTime = list.get(i).getXs().shortValue();
            }
            Map<String, Object> map2 = new HashMap<>();
            map2.put("pxnd", list.get(i).getPxnd());
            map2.put("pxlx", list.get(i).getPxlx());
            map2.put("pxzt", list.get(i).getPxzt());
            map2.put("pxjg", list.get(i).getPxjg());
            String str = "";
            if (list.get(i).getKsrq() != null) {
                str = str + DateUtil.dateToString(list.get(i).getKsrq(), "yyyy-MM-dd") + "--";
            }
            if (list.get(i).getJzrq() != null) {
                str = str + DateUtil.dateToString(list.get(i).getJzrq(), "yyyy-MM-dd");
            }
            map2.put("ksrq_jzrq", str);
            map2.put("xt", list.get(i).getXt());
            map2.put("xs", list.get(i).getXs());
            listMap2.add(map2);
            if (i == list.size() - 1) {
                map.put("year", Short.valueOf(year));
                map.put("yearTime", Short.valueOf(yearTime));
                map.put("pxList", listMap2);
                listMap.add(map);
            }
            sumTime = (short) (sumTime + list.get(i).getXs().shortValue());
        }
        j.put("sumTime", Short.valueOf(sumTime));
        j.put("timeList", listMap);
        return R.ok().put("data", (Object) j);
    }
}
